package im.oen.boot.api.entity;

import im.oen.boot.common.constant.Magic;
import im.oen.boot.common.data.Base;
import im.oen.boot.common.utils.DateUtil;
import im.oen.boot.common.utils.UUID;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

/**
 * @author Kevin.Xu
 */
@MappedSuperclass
public abstract class AbsEntity extends Base {

    /**
     * 数据UUID
     */
    @Column(name = "uuid", unique = true, columnDefinition = " varchar(50) not null comment '数据UUID'")
    private String uuid;
    /**
     * 数据状态 (-1 表示已删除)
     */
    @Column(name = "state", columnDefinition = " tinyint not null comment '数据状态'")
    private Integer state;
    /**
     * 数据创建时间
     */
    @Column(name = "created", columnDefinition = " bigint(15) not null comment '数据创建时间'")
    private Long created;
    /**
     * 日期 20210501
     */
    @Column(name = "created_fmt", columnDefinition = " bigint(9) not null comment '日期 20210501'")
    private Long createdFmt;
    /**
     * 数据最后一次更新时间
     */
    @Column(name = "updated", columnDefinition = " bigint(15) not null comment '数据最后一次更新时间'")
    private Long updated;
    /**
     * 数据最后一次更新的用户ID
     */
    @Column(name = "updater", columnDefinition = " bigint(18) null comment '数据最后一次更新的用户ID'")
    private Long updater;

    public AbsEntity() {
    }

    public AbsEntity(boolean init) {
        if (init) {
            this.init(null);
        }
    }

    public void init(Long updater) {
        long current = DateUtil.currentTimeMillis();
        this.uuid = UUID.uuid();
        this.state = Magic.ENABLE;
        this.created = current;
        this.createdFmt = DateUtil.fmtYYYYMMDD(current);
        this.updated = current;
        this.updater = updater;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Long getCreated() {
        return created;
    }

    public void setCreated(Long created) {
        this.created = created;
    }

    public Long getCreatedFmt() {
        return createdFmt;
    }

    public void setCreatedFmt(Long createdFmt) {
        this.createdFmt = createdFmt;
    }

    public Long getUpdated() {
        return updated;
    }

    public void setUpdated(Long updated) {
        this.updated = updated;
    }

    public Long getUpdater() {
        return updater;
    }

    public void setUpdater(Long updater) {
        this.updater = updater;
    }
}
